home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / blitzblank / sources / bb.aquarium < prev    next >
Text File  |  1993-09-17  |  6KB  |  305 lines

  1. CloseEd
  2.  
  3. NEWTYPE.spritedata
  4. a.w
  5. b
  6. c
  7. d
  8. e
  9. f
  10. End NEWTYPE
  11.  
  12. NEWTYPE.tags
  13. a.l
  14. b
  15. c
  16. d
  17. e
  18. f
  19. End NEWTYPE
  20.  
  21. DEFTYPE.spritedata *sprdata
  22. DEFTYPE.Screen *myscreen,*myscreen2
  23. DEFTYPE.NewScreen newscreen
  24. DEFTYPE.Window *mywindow
  25. DEFTYPE.NewWindow newwindow
  26. DEFTYPE.Message *msg
  27. DEFTYPE.MsgPort *port
  28. DEFTYPE.tags tags
  29. DEFTYPE.l
  30.  
  31. Statement stringborder{x,y,w,h}
  32. Wline x+1,y+h+2,x+1,y,x+w+8,y,1
  33. Wline x+w+10,y-1,x+w+10,y+h+4,x-1,y+h+4,1
  34. Wline x,y+h+3,x,y,1
  35. Wline x+w+11,y-1,x+w+11,y+h+4,1
  36. Wline x-1,y+h+3,x-1,y-1,x+w+10,y-1,2
  37. Wline x+w+9,y,x+w+9,y+h+3,x+1,y+h+3,2
  38. Wline x-2,y+h+4,x-2,y-1,2
  39. Wline x+w+8,y+1,x+w+8,y+h+2,2
  40. End Statement
  41.  
  42.  
  43. Select Par$(1)
  44.   Case "BLANK"
  45.  
  46.     name$="BB.BlankModule"+Chr$(0)
  47.     *port=CreateMsgPort_()
  48.     *port\mp_Node\ln_Name=&name$
  49.     *port\mp_Node\ln_Pri=1
  50.     AddPort_ *port
  51.  
  52.     SetTaskPri_ FindTask_(0),Val(Par$(8))
  53.     fish=1
  54.     Gosub readconfig
  55.     *sprdata=AllocMem_(SizeOf.spritedata,#MEMF_CHIP|#MEMF_CLEAR)
  56.     newwindow\LeftEdge=0,0,1,1
  57.     newwindow\Flags=#WFLG_ACTIVATE
  58.     newwindow\FirstGadget=0,0,0,0,0,-1,-1,-1,-1,#WBENCHSCREEN
  59.  
  60.     *mywindow=OpenWindow_(newwindow)
  61.  
  62.     SetPointer_ *mywindow,*sprdata,0,0,0,0
  63.  
  64.     width=Val(Par$(2))+280
  65.     height=Val(Par$(3))
  66.     mode=Val(Par$(4))
  67.     monitor=Val(Par$(5))
  68.     depth=3
  69.     title$="BB.Aquarium0"+Chr$(0)
  70.     newscreen\LeftEdge=-140,0,width+4,height,3
  71.     newscreen\ViewModes=0,#CUSTOMSCREEN|#SCREENBEHIND,0,&title$
  72.     tags\a=#SA_DisplayID
  73.     tags\b=$10000*monitor+mode
  74.     tags\c=0
  75.     *myscreen=OpenScreenTagList_(newscreen,tags)
  76.  
  77.     title2$="BB.Aquarium1"+Chr$(0)
  78.     newscreen\ViewModes=0,#CUSTOMSCREEN|#SCREENBEHIND,0,&title2$
  79.     *myscreen2=OpenScreenTagList_(newscreen,tags)
  80.  
  81.  
  82.     shapes=19
  83.     mh=4
  84.  
  85.     If height<300
  86.       mh/2
  87.     EndIf
  88.  
  89.     If *myscreen<>0 AND *myscreen2<>0
  90.  
  91.       LoadShapes 1,shapes,path$+"BB.Aquarium.data"
  92.       LoadShape 10,path$+"BB.Aquarium.pal",0
  93.       For i=1 To shapes
  94.         If height<300
  95.           Scale i,1,0.5,0
  96.         EndIf
  97.         MidHandle i
  98.         CopyShape i,20+i
  99.         XFlip 20+i
  100.         MidHandle 20+i
  101.       Next i
  102.  
  103.       Handle 10,0,0
  104.  
  105.       For i=0 To 1
  106.         FindScreen i,"BB.Aquarium"+Str$(i)
  107.         ScreensBitMap i,i
  108.         Use Palette 0
  109.         Boxf 0,0,width-1,height-1,0
  110.       Next i
  111.       Use BitMap 0
  112.       Dim x.q(fish+1)
  113.       Dim y.q(fish+1)
  114.       Dim r.q(fish+1)
  115.       Dim s(fish+1)
  116.       Dim ya.q(fish+1)
  117.       Dim dy.q(fish+1)
  118.  
  119.       Queue 0,fish+1
  120.       Queue 1,fish+1
  121.  
  122.  
  123.       Repeat
  124.         UnQueue sc
  125.         For i=1 To fish
  126.           If r(i)=0
  127.             If 1 ;Rnd(50)<1
  128.               s(i)=Rnd(shapes-10)+1
  129.               r(i)=Int(Rnd(2))
  130.               If r(i)=0
  131.                 r(i)=-1
  132.                 x(i)=width-70
  133.               Else
  134.                 x(i)=70
  135.               EndIf
  136.               y(i)=Rnd(height-ShapeHeight(s(i))-4-mh)+ShapeHeight(s(i))/2+mh
  137.               r(i)*(Rnd(1)+0.5)
  138.               ya(i)=y(i)
  139.               dy(i)=r(i)/3
  140.             EndIf
  141.           Else
  142.             ya(i)+dy(i)
  143.             If ya(i)>y(i)+mh OR ya(i)<y(i)-mh
  144.               If s(i)<10
  145.                 s(i)+10
  146.               Else
  147.                 s(i)-10
  148.               EndIf
  149.               dy(i)=-dy(i)
  150.               ya(i)+2*dy(i)
  151.             EndIf
  152.             x(i)+r(i)
  153.             If r(i)<0
  154.               If x(i)>70
  155.                 QBlit sc,s(i),x(i)+0.5,ya(i)+0.5
  156.               Else
  157.                 r(i)=0
  158.               EndIf
  159.             Else
  160.               If x(i)<width-70
  161.                 QBlit sc,20+s(i),x(i)+0.5,ya(i)+0.5
  162.               Else
  163.                 r(i)=0
  164.               EndIf
  165.             EndIf
  166.           EndIf
  167.         Next i
  168.         If yb=0
  169.           yb=height-ShapeHeight(10)
  170.           xb=Rnd(width/2)+width/4
  171.         Else
  172.           yb-1
  173.           QBlit sc,10,xb,yb
  174.         EndIf
  175.         ShowScreen sc
  176.         sc=1-sc
  177.         Use BitMap sc
  178.  
  179.         *msg=GetMsg_(*port)
  180.  
  181.       Until *msg
  182.  
  183.     EndIf
  184.     CloseScreen_ *myscreen
  185.     CloseScreen_ *myscreen2
  186.  
  187.  
  188.     ClearPointer_ *mywindow
  189.     CloseWindow_ *mywindow
  190.     FreeMem_ *sprdata,SizeOf.spritedata
  191.     RemPort_ *port
  192.     DeleteMsgPort_ *port
  193.  
  194.   Case "INFO"
  195.  
  196.     title$="Aquarium"+Chr$(0)
  197.     reqtext$="Aquarium - Module for BlitzBlank"+Chr$(10)
  198.     reqtext$+Chr$(169)+" 1993 by Thomas Brkel"+Chr$(10)
  199.     reqtext$+"Graphics by Michael Weber"+Chr$(10)+Chr$(10)
  200.     reqtext$+"Fishes are swimming on a 8-color-screen"+Chr$(10)
  201.     reqtext$+"with doublebuffering. Much CHIP-RAM needed."+Chr$(10)
  202.     reqtext$+"Aquarium is not compatible with graphic-cards."+Chr$(10)+Chr$(10)
  203.     reqtext$+"Choose the number of fishes in the config-window."+Chr$(0)
  204.  
  205.     gadget$="OK"+Chr$(0)
  206.  
  207.     easy.EasyStruct\es_StructSize=SizeOf.EasyStruct
  208.     easy\es_Title=&title$
  209.     easy\es_TextFormat=&reqtext$
  210.     easy\es_GadgetFormat=&gadget$
  211.  
  212.     EasyRequestArgs_ 0,easy,0,0
  213.  
  214.   Case "CONFIG"
  215.     *myscreen=LockPubScreen_(0)
  216.     width=*myscreen\Width
  217.     height=*myscreen\Height
  218.     font=*myscreen\Font\ta_YSize
  219.     Gosub readconfig
  220.     WbToScreen 0
  221.     BorderPens 0,0
  222.     StringGadget 0,100,25,0,0,3,30
  223.     Window 0,width/2-90,height/2-25,180,50,$100e,"Aquarium",1,2,0
  224.     stringborder{100,25,30,8}
  225.     WColour 2
  226.     WLocate 40,24-font
  227.     Print "Fish:"
  228.     WLocate 40,24-font+8
  229.     Print "(1-10)"
  230.     SetString 0,0,Str$(fish)
  231.     ActivateString 0,0
  232.     Repeat
  233.       ev=WaitEvent
  234.     Until ev=$200 OR ev=$40
  235.     fish=Val(StringText$(0,0))
  236.     Free Window 0
  237.     Gosub writeconfig
  238.     UnlockPubScreen_ 0,*myscreen
  239.  
  240. End Select
  241.  
  242. End
  243.  
  244.  
  245.  
  246.  
  247. .readconfig
  248. path$=Par$(9)
  249. For i=10 To NumPars
  250.   path$=path$+" "+Par$(i)
  251. Next i
  252. If ReadFile(0,path$+"BB.Modules.config")
  253.   FileInput 0
  254.   While NOT Eof(0)
  255.     If Edit$(100)="*** Aquarium ***"
  256.       fish=Edit(5)
  257.     EndIf
  258.   Wend
  259.   DefaultInput
  260.   CloseFile 0
  261. EndIf
  262. Gosub checkval
  263. Return
  264.  
  265.  
  266. .writeconfig
  267. Gosub checkval
  268. If ReadFile(0,path$+"BB.Modules.config")
  269.   If WriteFile(1,path$+"BB.Modules.temp")
  270.     FileInput 0
  271.     FileOutput 1
  272.     While NOT Eof(0)
  273.       f$=Edit$(100)
  274.       If f$="*** Aquarium ***"
  275.         Repeat
  276.           f2$=Edit$(100)
  277.         Until Eof(0) OR Left$(f2$,3)="***"
  278.         If NOT Eof(0) Then NPrint f2$
  279.       Else
  280.         NPrint f$
  281.       EndIf
  282.     Wend
  283.     CloseFile 1
  284.   EndIf
  285.   CloseFile 0
  286. EndIf
  287. KillFile path$+"BB.Modules.config"
  288. f$=path$+"BB.Modules.temp"+Chr$(0)
  289. f2$=path$+"BB.Modules.config"+Chr$(0)
  290. Rename_ &f$,&f2$
  291. If OpenFile(0,path$+"BB.Modules.config")
  292.   FileOutput 0
  293.   FileSeek 0,Lof(0)
  294.   NPrint "*** Aquarium ***"
  295.   NPrint fish
  296.   CloseFile 0
  297. EndIf
  298. Return
  299.  
  300. .checkval
  301. If fish<1 Then fish=3
  302. If fish>10 Then fish=3
  303. Return
  304.  
  305.